// let base ="http://127.0.0.1:3303/api"
let base = "http://116.198.252.65:3303/api"
export default (url, params) => {
	url = base + url
	return new Promise((resolve, reject) => {
		let tokenStorageKey = "tarde-token"
		let token = uni.getStorageSync(tokenStorageKey)
		uni.request({
			...params,
			url,
			header:{
				"tarde-token":token
			},
			success: (res) => {
				let {
					statusCode,
					data,
					cookies,
					errMsg,
					header
				} = res
				
				if(statusCode == 200){
					let {code,msg} = data
					if(code == 0){
						resolve(data)
					}else{
						uni.showToast({
							title:msg,
							icon:"error"
						})
						reject(data)
					}
				}else if(statusCode == 403){
					let {code,msg} = data
					uni.navigateTo({
						url:"/pages/login/login"
					})
					uni.showToast({
						title:msg,
						icon:"none"
					})
				}else{
					throw {
						code:statusCode,
						msg:"请求出错,未知错误"
					}
				}
			},
			fail: (err) => {
				reject(err)
			}
		})
	})
}